import React from "react";
import { observer } from "mobx-react-lite";
import { useStor } from "../../store/index";
import { Navigate } from "react-router-dom";

function Auth({ children }) {
    const { userStroe } = useStor();
    // console.log(userStore.user.token);
    // 如果存在token  则证明已经 登录 ，正常显示子组件 ，如果没有登录 跳转回登录页
    if (userStroe.user.token) {
        return children;
    } else {
        return <Navigate to="/login" />;
    }
}

export default observer(Auth);